﻿using Volo.Abp.DependencyInjection;
using YAPACS.Workflows;

namespace YAPACS.RisServer.Workflows.Report;

public class BeforeSubmit : WorkflowBase, IBeforeSubmit, ITransientDependency
{
    protected override async Task<WorkflowOutput> InvokeCoreAsync(WorkflowInput input)
    {
        const string key = "Report";
        if (input.ContainsKey(key) && input.GetValueOrDefault(key) is BusinessObjects.Exams.Report report)
        {
            if (report.ExamResult == null)
            {
                throw new Exception("请选择【检查结果】");
            }
            if (string.IsNullOrWhiteSpace(report.ImageSeeing))
            {
                throw new Exception("【影响所见】不能为空");
            }
            if (string.IsNullOrWhiteSpace(report.ImageDiagnosis))
            {
                throw new Exception("【影像诊断】不能为空");
            }
            return await Task.FromResult(new WorkflowOutput() { Success = true });
        }
        return new WorkflowOutput
        {
            Success = false,
            Error = "未获取到报告数据"
        };
    }
}

